package com.example.demo.mapper;

import com.example.demo.pojo.entity.Report;
import com.example.demo.pojo.vo.CommentReportVO;
import com.example.demo.pojo.vo.ItemReportVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ReportMapper {
    @Insert("insert into report(item_id, reason, image, create_time, update_time) values (#{itemId}, #{reason}, #{image}, now(), now())")
    boolean addItemReport(Long itemId, String reason, String image);

    @Insert("insert into report(comment_id, reason, image, create_time, update_time) values (#{commentId}, #{reason}, #{image}, now(), now())")
    boolean addCommentReport(Long commentId, String reason, String image);

    @Delete("delete from report where item_id = #{itemId}")
    boolean deleteReportByItemId(Long itemId);

    @Delete("delete from report where comment_id = #{commentId}")
    boolean deleteReportByCommentId(Long commentId);

    @Delete("delete from report where id = #{id}")
    boolean deleteReportById(Long id);

    @Select("select id from report where comment_id = #{commentId}")
    List<Long> selectIdListByCommentId(Long commentId);

    @Select("select id from report where item_id = #{itemId}")
    List<Long> selectIdListByItemId(Long itemId);

    @Select("select item_id, reason, image, create_time from report where item_id is not null order by create_time asc")
    Page<ItemReportVO> selectItemReport();

    @Select("select comment_id, comment.item_id, reason, image, report.create_time " +
            "from report inner join comment on report.comment_id=comment.id " +
            "where comment_id is not null order by report.create_time asc")
    Page<CommentReportVO> selectCommentReport();
}
